package com.ljf.interestingmaps.nearby;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.ljf.interestingmaps.R;

import java.util.ArrayList;
import java.util.List;

public class NearActivity extends AppCompatActivity implements View.OnClickListener{

    public static final int PLACE_PICKER_REQUEST = 1;

    private List<NearbyItem> itemList = new ArrayList<>();


    private GridView gridView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_near);
        itemList.add(new NearbyItem(R.mipmap.clothes,"Clothing Store"));
        itemList.add(new NearbyItem(R.mipmap.cafe,"Cafe"));
        itemList.add(new NearbyItem(R.mipmap.stadium,"Stadium"));
        itemList.add(new NearbyItem(R.mipmap.shopping_cart,"Shopping Mall"));
        itemList.add(new NearbyItem(R.mipmap.university,"University"));
        itemList.add(new NearbyItem(R.mipmap.bus_stop,"Bus Stop"));
        itemList.add(new NearbyItem(R.mipmap.salon,"Beauty Salon"));
        itemList.add(new NearbyItem(R.mipmap.airport,"Airports"));
        itemList.add(new NearbyItem(R.mipmap.pet_1,"Pet Store"));
        itemList.add(new NearbyItem(R.mipmap.pharmacy,"Pharmacy"));
        itemList.add(new NearbyItem(R.mipmap.zoo,"Zoo"));
        itemList.add(new NearbyItem(R.mipmap.hospital,"Hospital"));
        itemList.add(new NearbyItem(R.mipmap.atm,"AtMs"));
        itemList.add(new NearbyItem(R.mipmap.dentist,"Dentist"));
        itemList.add(new NearbyItem(R.mipmap.jewelry,"Jewelry Store"));
        itemList.add(new NearbyItem(R.mipmap.bank,"Banks"));
        itemList.add(new NearbyItem(R.mipmap.church,"Church"));
        itemList.add(new NearbyItem(R.mipmap.fire_station,"Fire Station"));
        itemList.add(new NearbyItem(R.mipmap.police_station,"Police Station"));
        itemList.add(new NearbyItem(R.mipmap.doctor,"Doctor"));
        itemList.add(new NearbyItem(R.mipmap.hotel,"Hotels"));
        itemList.add(new NearbyItem(R.mipmap.mosque,"Mosques"));
        itemList.add(new NearbyItem(R.mipmap.park,"Parks"));
        itemList.add(new NearbyItem(R.mipmap.bakery,"Bakery"));
        itemList.add(new NearbyItem(R.mipmap.gas_station,"Gas Station"));
        itemList.add(new NearbyItem(R.mipmap.shoes_store,"Shoe Store"));
        itemList.add(new NearbyItem(R.mipmap.post_office,"Post Office"));
        itemList.add(new NearbyItem(R.mipmap.school,"School"));

        gridView = (GridView) findViewById(R.id.gridView);
        gridView.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return itemList.size();
            }

            @Override
            public Object getItem(int position) {
                return null;
            }

            @Override
            public long getItemId(int position) {
                return 0;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {

                View view = LayoutInflater.from(NearActivity.this).inflate(R.layout.nearby_item,null);

                ImageView icon = (ImageView) view.findViewById(R.id.icon);
                TextView titleView = (TextView) view.findViewById(R.id.titleTv);
                final NearbyItem item = itemList.get(position);
                icon.setBackgroundResource(item.iconId);
                titleView.setText(item.title);
                view.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String uri = "http://maps.google.com/maps?q=" + item.title+"&hl=en";

                        Intent mapIntent =new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                        mapIntent.setPackage("com.google.android.apps.maps");
                        startActivity(mapIntent);
                    }
                });
                return view;
            }
        });

    }

    @Override
    public void onClick(View v) {

    }




    class  NearbyItem{
        int iconId;
        String title;

        public NearbyItem(int iconId,String title){
            this.iconId = iconId;
            this.title = title;
        }
    }
}
